package com.deyuanyun.pic.insp.service.inspresult.impl;

import com.deyuanyun.pic.common.tool.JXL;
import com.deyuanyun.pic.insp.mapper.DefectDepressedMapper;
import com.deyuanyun.pic.insp.service.inspresult.DepressedService;
import com.deyuanyun.pic.insp.util.InspExportUtil;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class DepressedServiceImpl extends BaseServiceImpl implements DepressedService {

	@Resource
	DefectDepressedMapper depressedMapper;
	
	@Override
	public Page<LinkedHashMap<String, Object>> findPage(HashMap param) {
		handlerParam(param);
		initPage();
		param.put("reference",getReference(param,"PIC_INSP_DEFECT_DEPRESSED"));
		Page<LinkedHashMap<String, Object>> data=depressedMapper.findPage(param);
		for(LinkedHashMap<String, Object> map:data)
		{
			map.put("REPAIR_SUGGESTION", CodeUtil.getName((String) map.get("REPAIR_SUGGESTION")));
		}
		return data;
	}

	@Override
	public List findObjectList(HashMap param) {
		handlerParam(param);

		//获取导出字段列表
		String filedList = InspExportUtil.getFiledList("DEPRESSED");

		//获取参考信息列表
		String reference = InspExportUtil.getReference(filedList,param);
		param.put("fileds",filedList);
		param.put("reference",reference);


		Page<LinkedHashMap<String,Object>> data=depressedMapper.findPageExport(param);

		return data;
	}

	@Override
	public List<List<String[]>> queryExportApprarse(HashMap param) {
		handlerParam(param);
		Page<LinkedHashMap<String,Object>> data=depressedMapper.queryExportApprarse(param);
		for(LinkedHashMap m:data){
			m.remove("IDDS");
			if(null != m.get("R6"))
			{
				m.put("R6",((BigDecimal)m.get("R6")).setScale(3,   BigDecimal.ROUND_HALF_UP).doubleValue());
			}
		}
		List<List<String[]>> result=new ArrayList<List<String[]>>();
		List<String[]> lsr = JXL.toList(data, "yyyy-MM-dd");
		result.add(lsr);
		return result;
	}

}
